package cn.wonderland.web.controller;

import cn.wonderland.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/{userId}")
    @SentinelResource(value="user-server-getById", blockHandler = "degradationMethod")
    public User getUser(@PathVariable("userId") Long userId) {
        return new User(11L,"杨木木彡","厕所1号坑","男");
    }


    /**
     * 服务降级方法
     * @param e 服务降级方法必须接收的异常参数
     */
    public User degradationMethod(@PathVariable("id") Long id, BlockException e){
        e.printStackTrace();
        return new User(-1L, "当前服务流量过大，请稍后重试！",null,null);
    }
}
